<?php
	
	// Integrimi i skedave sistemore
    include('../include/functions.inc.php');
	include('../include/template.class.php');
	
	
	// DB CONNECT
	dbOpen("dielli");
	
	
	// PROJECT
	$PROJECT = setProject();
	
	
	// Data e sotme
	$today = strtotime("now");
	
	
	// Ndyshoret primare
	define('TPL','../include/styles/'.$PROJECT['style'].'/dielli/pending.html');
	define('FILENAME',basename($_SERVER["PHP_SELF"]));
	
	if (isset($_GET['id']))
		define('ID', $_GET['id']);
	else 
		define('ID', implode(mysql_fetch_assoc(mysql_query("SELECT id FROM pending WHERE pubdate > '".$today."' ORDER BY pubdate"))));
	
	// TMP CLASS
	$tmp = new Template(TPL,$PROJECT['lang']);
	
		
	// MENUES
	$tmp->setContent("CATEGORY",$tmp->menu("category","../dielli"));
	$tmp->setContent("DIELLI",$tmp->menu("dielli",FILENAME));
	$tmp->setContent("FOOTMENU",$tmp->menu("foot"));
	
	
	// ACCORDIONS
	$tmp->setContent("RANDOM",randomContent("dielli"));
	
	
	$query = mysql_query("SELECT * FROM pending WHERE pubdate > '".$today."' ORDER BY pubdate");
	
	
	if (mysql_num_rows($query) > 0) {
		
		$STORY = array();
		
		while ($row = mysql_fetch_assoc($query)) {
			
			// Konverto daten dhe perpuno permbajtjen
			$row['date'] = setDate($row['pubdate']);
			$row['content'] = nl2br($row['content']);
			
			// Nese ka ndonje lajmerim qe eshte aktiv trego permbajtjen
			if (ID == $row['id'])
				$STORY = $row;
			elseif (empty($STORY))
				$STORY = $row;
			
			$row['class'] = (ID == $row['id']) ? "current" : null;
			
			$PENDING[] = $row;
			
			// Rikthej vleren e fushes boshe per xhvendosjen e bllokut
			$MESSAGE = array();
		}
		
	}
	else {
		
		// Trego porosin per arikeven boshe
		$MESSAGE = $tmp->xmlContent('nopending');
		
		// Rikthej vleren e fushes boshe per xhvendosjen e bllokut
		$PENDING = array();
		
		// Rikthej vleren e fushes boshe per xhvendosjen e bllokut
		$STORY = array();
	}
	
	
	// STORY
	$tmp->setContent("STORY",$STORY);
	
	// NEWS
	$tmp->setContent("PENDING",$PENDING);
	
	// STORY
	$tmp->setContent("MESSAGE",$MESSAGE);
	
	// LABELS
	$tmp->setLabels();
	
	
	// DISPLAY ALL						  
	echo $tmp->vorlage;
?>